package com.wteam.dragon.model.pojo.bean;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.gitee.sunchenbin.mybatis.actable.annotation.*;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant;
import com.wteam.dragon.system.basebean.bean.BaseBean;
import lombok.Data;

import java.util.Objects;
import java.util.Set;

/**
 * 菜单
 * @Author 陈晓辉
 * @Date 2020/3/23
 */
@Data
@Table
@TableName
public class Menu extends BaseBean {
    @IsKey
    @IsNotNull
    @IsAutoIncrement
    @TableId(type = IdType.AUTO)
    @ColumnType(MySqlTypeConstant.BIGINT)
    @Column(comment = "自增id")
    private Long id;

    @IsNotNull
    @ColumnType(MySqlTypeConstant.VARCHAR)
    @Column(comment = "菜单名称")
    private String title;

    @IsNotNull
    @DefaultValue("999")
    @ColumnType(MySqlTypeConstant.BIGINT)
    @Column(comment = "排序")
    private Long sort;

    @IsNotNull
    @ColumnType(MySqlTypeConstant.VARCHAR)
    @Column(comment = "路径名称")
    private String name;

    @IsNotNull
    @ColumnType(MySqlTypeConstant.VARCHAR)
    @Column(comment = "权限标识")
    private String permission;

    @ColumnType(MySqlTypeConstant.VARCHAR)
    @Column(comment = "图标标识")
    private String icon;

    @IsNotNull
    @DefaultValue("0")
    @ColumnType(MySqlTypeConstant.TINYINT)
    @Column(comment = "是否缓存")
    private Boolean cache;

    @IsNotNull
    @DefaultValue("0")
    @ColumnType(MySqlTypeConstant.TINYINT)
    @Column(comment = "是否隐藏")
    private Boolean hidden;

    @IsNotNull
    @ColumnType(MySqlTypeConstant.BIGINT)
    @Column(comment = "父id")
    private Long pid;

    @IsNotNull
    @DefaultValue("0")
    @ColumnType(MySqlTypeConstant.TINYINT)
    @Column(comment = "外链")
    private Boolean iframe;

    @ColumnType(MySqlTypeConstant.VARCHAR)
    @Column(comment = "子路由")
    private String child;


    /**
     * 对应的角色id（可以操作的角色id）
     */
    @TableField(exist = false)
    private Set<Role> roles;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Menu menu = (Menu) o;
        return Objects.equals(id, menu.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
